/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DBTables;

import DBManager.*;
import java.sql.PreparedStatement;
import java.sql.Connection;
import java.sql.ParameterMetaData;
import java.sql.SQLException;

/**
 *Класс таблицы User_Group
 * @author Иван
 */
public class TUserGroup extends DataManager {

    public String Description;

    public TUserGroup(Connection conn, String tableName) throws SQLException {
        super(conn, tableName);

        SelectPrepStatement = connection.prepareStatement("select * from " + TableName);
        InsertPrepStatement = connection.prepareStatement("insert into " + TableName + " (Description) values (?) ");
        UpdatePrepStatement = connection.prepareStatement("update " + TableName + " set Description = ? Where Id_Command = ?");
        DeletePrepStatement = connection.prepareStatement("delete from " + TableName + " where Id_Command = '" + ID_Table + "' ");
    }

    @Override
    public void SetValues(PreparedStatement prepareStatement) throws SQLException {

        ParameterMetaData metaData = prepareStatement.getParameterMetaData();
        int countParameters = metaData.getParameterCount();

        if (countParameters >= 1) // for insert prepared statement
        {
            prepareStatement.setString(1, Description);

        }

        if ((countParameters == 2))// for update prepared statement
        {
            prepareStatement.setString(2, ID_Table);
        }



    }
}
